package com.itheima.utils;


import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

import java.util.Map;

public class JwtUtils {

    private static final String SECRET_KEY = "aXRoZWltYQ==";
    private static final long EXPERITIME=1000*60*60*12;


    public static String generateToken(Map<String,Object> claims){
        return Jwts.builder()
                .signWith(SignatureAlgorithm.HS256,  SECRET_KEY)
                .addClaims(claims)
                .setExpiration(new java.util.Date(System.currentTimeMillis()+EXPERITIME))
                .compact();
    }


    public static Claims parseToken(String token){
        return Jwts.parser()
                .setSigningKey(SECRET_KEY)
                .parseClaimsJws(token)
                .getBody();
    }
}
